package Dmusic.galaxy;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;

public class listAdapter extends BaseAdapter {
	private ArrayList<Item> ListItem;
	private LayoutInflater mInflater;
	public listAdapter(Context context ,ArrayList<Item> ListItem ){
		mInflater = LayoutInflater.from(context);
		this.ListItem = ListItem;
	}
	
	static class ViewHolder 
	{
	TextView name;
	ImageView icon;
	
	}
	

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return ListItem.size();
	
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position , View convertView, ViewGroup parent) {
		ViewHolder holder ;
		if (convertView == null ) {
			convertView = mInflater.inflate(R.layout.item, null);
			holder = new ViewHolder();
			holder.name = (TextView) convertView.findViewById(R.id.textView1);
			holder.icon = (ImageView) convertView.findViewById(R.id.imageView1);
			convertView.setTag(holder);
			
		}
		else {
		 holder = (ViewHolder)convertView.getTag();
		}
		if (position <ListItem.size()) {
			Item item = ListItem.get(position);
			Bitmap bmp = BitmapFactory.decodeFile(item.image);
			holder.icon.setImageBitmap(bmp);
			holder.name.setText(item.name);
		}
		// TODO Auto-generated method stub
		return convertView;
	}

}
